from socket import *
import time

#用于UDP发送警报
def send_udp_alerts(alerts):
    alerts_socket = socket(AF_INET, SOCK_DGRAM)
    addr = ('192.168.170.32', 7788)
    #while True:
    if alerts == '1':
        print(alerts)
    alerts_socket.sendto(alerts.encode('utf-8'), addr)
    time.sleep(0.1)
    alerts_socket.close()

# 用于tcp发送警报

# def send_tcp_alerts(alerts):
#     alerts_socket = socket(AF_INET, SOCK_STREAM, 0)
#     addr = ('192.168.84.32', 7788)
#     #while True:
#     if alerts == '1':
#         print(alerts)
#     alerts_socket.connect(addr)
#     alerts_socket.send(alerts.encode('utf-8'))
#     time.sleep(0.1)
#     alerts_socket.close()

# if __name__ == '__main__':
#     # send_udp_alerts()
#     send_tcp_alerts()